<template>
  <div class="myContailer">
    <el-row class="myTitleBorderBottom">
      <el-col :span="12" class="myLineHeight_40px">{{title}}</el-col>
      <el-col :span="12" class="myTextAlignRight">
        <el-button type="primary" class="myBgGreen">下载导入模板</el-button>
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px">
      <el-upload
        class="upload-demo"
        name="uploadFile"
        :on-error="errorUpload"
        :on-success="successUpload"
        :show-file-list="false"
        :action="HOUES_DATA_UPLOAD"
        :limit="1">
        <el-button type="primary" class="myBgGreen">点击上传</el-button>
      </el-upload>
      <div class="msgbox">
        {{msg}}
      </div>
    </el-row>
  </div>
</template>

<style scoped>
  .myContailer{
    background: #fff;
    padding: 10px;
  }
  .myTitleBorderBottom{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 1px solid #dbdbdb;
    padding-bottom: 5px;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top:2px;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myMarginTop_10px{
    margin-top: 10px;
  }
  .msgbox{
    width: 600px;
    height: 300px;
    border:1px solid #ccc;
    border-radius: 5px;
    margin-top: 10px;
    padding: 10px;
    box-sizing: border-box;
    word-wrap: break-word;
    white-space: pre;
  }
</style>

<script>
  import { HOUES_DATA_UPLOAD } from '@/config/baseUrl';
  export default {
    data(){
      return{
        title:"房屋数据导入",
        msg:'',
        HOUES_DATA_UPLOAD:HOUES_DATA_UPLOAD
      }
    },      
    created(){
      document.title=this.title;

    },
    filters: {
      
    },
    methods:{
      successUpload(response, file, fileList){
        this.msg=`上传成功!
        文件名: ${file.name}
        文件大小: ${parseInt(file.size/1024)}KB
        返回信息: ${response.result}`;
      },
      errorUpload(err, file, fileList){
        let errlist=(err+'').split(' ');
        let errmsg=JSON.parse(errlist[errlist.length-1]).error_msg;
        this.msg=`上传失败!
        返回信息: ${errmsg}`;
      }
    }
  }
</script>



